package com.example.natatorium_management.contorller;

import com.example.natatorium_management.entity.User;
import com.example.natatorium_management.result.appexception.AppException;
import com.example.natatorium_management.result.restful.R;
import com.example.natatorium_management.result.restful.ResponseEunm;
import com.example.natatorium_management.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/User")
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping("/findAll")
    public List<User> findAll() throws Exception {
        return userService.findAll();
    }

    /**
     * 登录验证
     * @param user user对象
     * @return 返回数据
     */
    @PostMapping ("/log")
    public R<User> logon(@RequestBody User user){
        return userService.logon(user);
    }

    /**
     * 注册
     * @param user w
     * @return w
     */
    @PostMapping("/register")
    public R<User> register(@RequestBody User user)  {
        return userService.register(user);
    }

    /**
     * 更新密码
     * @param user d
     * @return d
     */
    @PutMapping ("/updatePassword")
    public R<User> updatePassword(@RequestBody User user){
        return userService.updatePassword(user);
    }
}
